package edu.neumont.pro180._2009_q2;

import java.util.Collection;

import edu.neumont.pro180._2009_q2.interfaces.IGamePiece;

public abstract class GamePiece implements IGamePiece {
	private Square position;
	private Player player;
	
	public int getValue() {
		return 0;
	}

	public void setPlayer(Player player) {
		if (this.player != player) {
			this.player = player;
			if (player != null) {
				player.addGamePiece(this);
			}
		}
	}

	@Override
	public Player getPlayer() {
		return this.player;
	}

	@Override
	public abstract Collection<Square> getPossibleSquares();

	//@Override
	public boolean setPosition(Square position) {
		Square oldPosition = this.position;
		if (oldPosition != position) {
			if (oldPosition != null) {
				// Break the relationship
				this.position = null;
				oldPosition.setGamePiece(null).execute();
			}
			this.position = position;
			if (this.position != null) {
				this.position.setGamePiece(this).execute();
			}
		}

		return true;
	}

	protected Square getPosition() {
		return this.position;
	}

	@Override
	public Square getSquare() {
		return this.position;
	}

	@Override
	public GamePieceMove getMove(Square destination) {
		return new GamePieceMove(this, destination);
	}
}
